package com.mezz.bones.framework.base.util;

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;

/**
 * @Author: zhuang
 * @Date: 2024/17/6 17:33
 * @Description: TODO
 * @Version: 1.0
 **/

public class JasyptEncryptionUtil {


    public static String encrypt(String input,String secret) {
        StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
        encryptor.setPassword(secret);  // 设置加密密钥
        return encryptor.encrypt(input);
    }

    public static String decrypt(String encryptedInput,String secret) {
        StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
        encryptor.setPassword(secret);  // 设置解密密钥
        return encryptor.decrypt(encryptedInput);
    }

    public static void main(String[] args) {
        String plainText = "123456";  //原文

        //生产加密秘钥使用-Djasypt.encryptor.password=1717 环境变量指定
        String encryptedText = encrypt(plainText,"test");
        System.out.println("Encrypted text: " + encryptedText);

//        System.out.println(decrypt("ZqvSS0QP8rCLaqRA8YDOJA==","bones-secret"));
    }
}
